-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix minute calculation for a running timer #10
Fix minute calculation for a running timer #10
Conversation
…operly shows as :59 until hour is increased by one
Could we please add a test to cover this scenario? Thanks! |
Added the tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me! We should probably port this to clockwork and Harvestapp.
@KaylaKremer Thank you! |
const minutes = Math.round(total) % 60 | ||
let minutes = total % 60 | ||
if (minutes >= 59.5 && minutes < 60) { | ||
minutes = Math.floor(minutes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, we could just hardcode 59
here since it's a known value.
This is in response to an issue brought up on our mobile repo.
With a running timer, when the time changes from
1:59
to2:00
for example, the time briefly displays at1:00
instead of as2:00
until another minute goes by, reverting back to the correct display time of2:01
.This is due to the use of
Math.round
which causes the minutes to display as:00
a bit too soon before the hour calculation increases by 1 since it will round up when the remainder value is 59.5 or greater.I added an
if
conditional to instead useMath.floor
when the remainder value is between 59.5 and 60 to keep the value displaying as:59
until the hour value increases by 1.